package com.sds.shop.action;

import java.io.IOException;
import java.util.HashMap;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.sds.fw.mvc.Action;
import com.sds.fw.mvc.HttpUtil;
import com.sds.shop.dao.OrderDAO;
import com.sds.shop.vo.OrderVO;
import com.sds.shop.vo.ProductVO;

public class OrderAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		HttpSession session = request.getSession();
		HashMap<String, ProductVO> map = (HashMap<String, ProductVO>)session.getAttribute("basket");
				
		OrderVO order = new OrderVO();
		order.setOrd_no(((Integer.parseInt(OrderDAO.getInstance().getMaxOrdNo()) + 1) + ""));
		order.setMem_id(request.getParameter("memId"));
		order.setOrd_amt(Integer.parseInt(request.getParameter("totPrice")));
		order.setRcvr_nm(request.getParameter("rcvr_nm"));
		order.setRcvr_tel_no(request.getParameter("rcvr_tel_no"));
		order.setRcvr_addr(request.getParameter("rcvr_addr"));
		order.setDlv_corp_no("1");
		order.setDlv_req(request.getParameter("dlv_req"));
		order.setOrd_stat_cd("111");
		
		OrderDAO.getInstance().insertOrder(order);
		OrderDAO.getInstance().insertOrderProduct(order, map);
		
		session.removeAttribute("basket");
		
		HttpUtil.forward(request, response, "orderList.do?memId=" + request.getParameter("memId"));
	}

}
